#!/usr/bin/env python
# -*- coding: UTF-8 -*-
# import sys

# [ Imports ]
# import Quartz
# import fire
# import AppKit

from AppKit import NSWorkspace


# from Quartz.CoreGraphics import CGEventPostToPSN
# from Quartz.CoreGraphics import kCGMouseButtonLeft
# from Quartz.CoreGraphics import kCGMouseButtonDown
# from Quartz.CoreGraphics import kCGMouseButtonLeft
# from Quartz.CoreGraphics import CGEventCreateMouseEvent
# my_process = filter(lambda x: x, [x if x.get('NSApplicationName') == 'wine_tbc952360618Wine' else None for x in  NSWorkspace.sharedWorkspace().launchedApplications()])[0]
# print my_process
# high_psn = my_process.get('NSApplicationProcessSerialNumberHigh')
# low_psn = my_process.get('NSApplicationProcessSerialNumberLow')
# my_psn = (high_psn, low_psn)
# print high_psn,low_psn,my_psn
# posx=1
# posy=1
# theEvent = CGEventCreateMouseEvent(None, kCGMouseButtonLeft, (posx, posy), kCGMouseButtonLeft)
# CGEventPostToPSN(my_psn, theEvent)
# print NSWorkspace.sharedWorkspace().launchedApplications()


def getAppProcess(name):
    all_process = NSWorkspace.sharedWorkspace().launchedApplications()
    my_process = []
    for x in all_process:
        print "x:", x
        if x['NSApplicationName'] == name:
            my_process.append(x)
    print all_process
    return my_process[0] if len(my_process) > 0 else None

# my_process=getAppProcess('wine_tbc276575275Wine')
# print my_process
